<template>
    <div>
        <!-- 表头 -->
        <div class="Head" v-if="Head">
            <!-- 仓库名称 -->
            <div class="Cusgory">
                <span style="margin-right: 10px">所属仓库</span>
                <el-select v-model="adi.wId" placeholder="请选择仓库" style="margin-top: 10px">
                    <el-option v-for="item in ck" :key="item.wId" :label="item.name" :value="item.wId"></el-option>
                </el-select>
            </div>
            <!-- 货架名称 -->
            <div class="Cusgory">
                <span style="margin-right: 10px">操作类型</span>
                <el-select v-model="adi.cate" placeholder="请选择操作类型" style="margin-top: 10px">
                    <el-option v-for="item in options" :key="item.cate" :label="item.label" :value="item.cate"></el-option>
                </el-select>
            </div>
            <!-- 搜索，重置按钮 -->
            <div class="But">
                <el-button type="primary" icon="el-icon-search" @click="serch">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="Reset()">重置</el-button>
            </div>
        </div>
        <!-- 表 -->
        <div class="function" style="margin-top: 10px">
            <div style="float: right">
                <el-tooltip class="item" effect="dark" content="隐藏搜索" placement="top">
                    <el-button icon="el-icon-search" circle @click="Display()"></el-button>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="刷新" placement="top">
                    <el-button icon="el-icon-refresh" circle @click="Reset"></el-button>
                </el-tooltip>
            </div>
        </div>
        <el-table :data="tableData" class="content" :cell-style="rowClass" :header-cell-style="headClass">
                <el-table-column label="序号" type="index" :index="indexMethod"></el-table-column>
            <el-table-column prop="createTime" label="时间"></el-table-column>
            <el-table-column prop="wName" label="仓库"></el-table-column>
            <el-table-column prop="code" label="货架"></el-table-column>
            <el-table-column prop="name" label="货品名称"></el-table-column>
            <el-table-column prop="number" label="货品编号"></el-table-column>
            <el-table-column prop="packUnit" label="货品规格"></el-table-column>
            <el-table-column prop="category" label="发生数量"></el-table-column>
            <el-table-column prop="cate" label="操作类型">
              <template slot-scope="scope">
                    {{ scope.row.cate == 0 ? '入库' : scope.row.cate == 1 ? '出库' : '盘库' }}
                </template>
            </el-table-column>
            <el-table-column prop="category" label="操作人"></el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="block">
            <el-pagination
                background
                style="float: right"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page.pageNum"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
            >
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { listbook, listWarehouse } from '../../api/user.js';
export default {
    data() {
        return {
            // 表头隐藏
            Head: true,
            value: '',
            tableData: [],
            ck: [],
            // 分页
            page: {
                pageSize: 10,
                pageNum: 1
            },
            // 添加输入框
            adi: {
                // 地址
                address: null,
                // 类别
                category: null,
                // 条码
                code: null,
                // 联系人
                contacts: null,
                // 名称
                name: null,
                // 手机号码
                phone: null
            },
            options: [
                {
                    cate: '0',
                    label: '入库'
                },
                {
                    cate: '1',
                    label: '出库'
                },
                {
                    cate: '2',
                    label: '盘库'
                }
            ],
            total: null
        };
    },
    methods: {
        // 表头显示
        Display() {
            this.Head = !this.Head;
        },
        // 表头样式设置
        headClass() {
            return 'text-align: center;background:#F8F8F9;color:#515A6D;';
        },
        // 表格样式设置
        rowClass() {
            return 'text-align: center;';
        },
        // 分页点击
        indexMethod(index) {
            return (this.page.pageNum - 1) * this.page.pageSize + index + 1;
        },
        // 分页
        handleSizeChange(val) {
            this.page.pageSize = Number(val);
            console.log(`每页 ${val} 条`);
            this.Rean();
        },
        handleCurrentChange(val) {
            this.page.pageNum = Number(val);
            console.log(`当前页: ${val}`);
            this.Rean();
        },
        // 表格渲染
        Rean() {
            listbook(this.page).then((a) => {
                this.tableData = a.rows;
                this.total = a.total;
            });
        },
        rean() {
            listWarehouse(this.wId).then((res) => {
                this.ck = res.rows;
                console.log(res.rows);
            });
        },
        // 重置按钮
        Reset() {
            this.Rean();
            this.adi.wId = undefined;
        },
        // 搜搜
        serch(){
            listbook(this.adi).then((res)=>{
                this.tableData=res.rows
                console.log(res);
            })
        }
    },
    mounted() {
        this.Rean();
        this.rean();
    }
};
</script>

<style scoped>
.Head {
    height: 50px;
}
/* 客户类别 */
.Cusgory {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusgory span {
    display: block;
    height: 100%;
    line-height: 50px;
    font-weight: 800;
    color: #606266;
    float: left;
}
/* 客户名称 */
.Cusname {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusname span {
    display: block;
    height: 100%;
    line-height: 50px;
    font-weight: 800;
    color: #606266;
    float: left;
}
/* 搜素，重置按钮 */
.But {
    height: 100%;
    float: left;
}
.But button {
    margin-top: 10px;
}
</style>